<!DOCTYPE html>
<html lang="en">
<head>
	<#include "${managerViewPath}/include/macro.ftl"/>
  	<#include "${managerViewPath}/include/meta.ftl"/>  
</head>
<body>
<@ms.content>
		<@ms.contentBody>
			<@ms.contentNav title="服务公司管理"></@ms.contentNav >
			<@ms.contentPanel>
			
			<@ms.searchForm  name="searchForm" id="searchForm" action="${managerPath}/company/list.do">
							<@ms.text label="公司名称"  name="enterpriseName"  title="公司名称"  placeholder="公司名称" value="${enterpriseName?default('')}"   />			  
						<@ms.searchFormButton>
								<@ms.queryButton id="submitSearch"/>
						</@ms.searchFormButton>
				</@ms.searchForm>
			
				<@ms.panelNav>
					<@ms.panelNavBtnGroup>
						<@ms.panelNavBtnAdd  id="totalAdd" title=""/>
						<@ms.panelNavBtnDel  id="totalDelete"/>
					</@ms.panelNavBtnGroup>
				</@ms.panelNav>
	              <@ms.table head=['序号','公司名称','地址','联系人',"联系电话","<th style='text-align:center'>技师数量</th>","<th style='text-align:center'>操作</th>"] checkbox="checkbox">
	           			<#if jyEnterpriseList?has_content>
	           				<#list jyEnterpriseList as list>
	                    	<tr>
	                    	<td style="text-align:center;width:10%;">
	                    		<input type="checkbox" name="checkbox${list_index+1}" value="${list.id?default(0)}">
	                    	</td>
	                    	<td style="width:5%">
	                    	${list_index+1}
	                    	</td>
						        <td style="width:10%"> 
					                ${list.enterpriseName?default("暂无")}
						        </td> 
					            <td style="width:10%">${list.enterpriseAddress?default("暂无")}</td>
					 			<td style="width:25%">${list.contactPserson?default("暂无")}</td>
					            <td style="width:10%" >${list.tel?default("暂无")}</td>
					            <td class="text-center">${list.count}</td>
					            <td class="text-center">
					            <a href = 'javascript:f(${list.id})'>操作</>
					            </td>
					         </tr>
	                    	</#list>
	                 		<#else>
	                 			<tr>
						            <td colspan="8" class="text-left">
						            	<@ms.nodata/>
									</td>
					          	</tr>
	        			</#if>
	        			</@ms.table>
	        			<#if page?has_content>
	        			<@ms.pagehelper page=page url="${managerPath}/company/list.do?${params}"/>
	        			</#if>	
			</@ms.contentPanel>		
		</@ms.contentBody>
		<!--=================模态框部分开始=================-->
		
		<!--修改/保存的模态框开始-->
		<@ms.modal modalName="update" title="">
			 <@ms.modalBody height="250">
				<@ms.form isvalidation=true name="updateTechnician" id="updateTechnician"  action="">	
		    		<@ms.text name="enterpriseName"    label="公司名称" title="公司名称" maxlength="100" placeholder="请输入公司名称" validation={"required":"true", "data-bv-notempty-message":"公司名称不能为空"}/>
		    		<@ms.text name="enterpriseAddress"    label="地址" title="地址"  maxlength="11" placeholder="请输入地址" validation={"required":"true", "data-bv-notempty-message":"地址不能为空"}/>
					<@ms.text name="contactPserson"    label="联系人" title="联系人"  maxlength="11" placeholder="请输入联系人" validation={"required":"true", "data-bv-notempty-message":"联系人不能为空"}/>
		    		<@ms.text name="tel"    label="电话" title="电话"  maxlength="11" placeholder="请输入电话" validation={"required":"true", "data-bv-notempty-message":"电话不能为空"}/>
		    	</@ms.form>		          	
		     </@ms.modalBody>
		     <@ms.modalButton>
	 			<@ms.savebutton id="updateButton"/>  
	 		 </@ms.modalButton>
	 		
		</@ms.modal>
		<!--修改/保存的模态框结束-->
		
		<!--多选删除的模态框开始-->
		<@ms.modal modalName="deleteAll" title="批量删除技师">
			 <@ms.modalBody>
				您确定删除您所勾选的技师吗？
		     </@ms.modalBody>
		     <@ms.modalButton>
	    		<@ms.button value="返回" id="closeDelete"/>  
	 			<@ms.button class="btn btn-danger" id="deleteButton" value="删除"/>  
	 		 </@ms.modalButton>
		</@ms.modal>
		<!--多选删除的模态框结束-->
		<!--单个删除的模态框开始-->
		<@ms.modal modalName="deleteRadio" title="删除技师">
			 <@ms.modalBody>
				您确定删除您所勾选的技师吗？
		     </@ms.modalBody>
		     <@ms.modalButton>
	    		<@ms.button value="返回" id="closeRadio"/>  
	 			<@ms.button class="btn btn-danger" id="deleteRadio" value="删除"/>  
	 		 </@ms.modalButton>
		</@ms.modal>
		<!--单个删除的模态框结束-->
		<!--=================模态框部分结束=================-->
		</@ms.content>
</body>
<script>
		$("#submitSearch").click(function() {
				$("#searchForm")[0].submit();
			});
			
		var f = function(a){
			
			window.location.href = "${managerPath}/company/getTechnicianlistById.do?id="+a;
			
		}
			
			
			
			
			var URL='';
	//模态框的操作
	$(function () {	
		$("#totalAdd").click(function(){
			$("#updateTitle").text("企业新增");	
			$("#updateButton").text("保存");
			URL="${managerPath}/company/save.do";
	 		$(".update").modal();
	 	});
	 	$("#closeUpdate").click(function(){
	 		$(".update").modal("hide");
	 	});
	 	
	 	$("#closeDelete").click(function(){
	 		$(".deleteAll").modal("hide");
	 	});
	 	
	 	$("#closeRadio").click(function(){
	 		$(".deleteRadio").modal("hide");
	 	});
	 	
	 	$("#closeSaveUrl").click(function(){
	 		$(".managerPageModel").modal("hide");
	 	});	
	});
	 	
 		//全选
	   	$("input[name='allCheckcheckbox']").on("click",function(){   
			if(this.checked){
			      $("input[name^='checkbox']").each(function(){this.checked=true;});
			}else{
			      $("input[name^='checkbox']").each(function(){this.checked=false;});   
			}   
		}); 
		
	 //点击更新按钮
	 $("#updateButton").click(function() {
			var formData = $("#updateTechnician").serialize();
			var vobj = $("#updateTechnician").data('bootstrapValidator').validate();
			var buttonHtml = $("#updateButton").html();
			if(vobj.isValid()){
					$.ajax({
					   type: "post",
					   dataType: "json",
					   url:  URL,
					   data: formData, 
					   beforeSend:function(){
					   		$("#updateButton").text($("#updateButton").text()+"中");
					   		$("#updateButton").attr("disabled",true);
					   },
					   success: function(msg){ 
					   		if(msg.result=="true"){
					   			alert(buttonHtml+"成功");
					   			location.reload();
					   		}else{
					   			alert(msg.resultMsg);
					   			$("#updateButton").text(buttonHtml);
					   			$("#updateButton").attr("disabled",false);
					   		}
					   },error: function(){
					   	  alert("数据请求失败，请检查请求地址和参数是否正确");
					   	  location.href = base+"${baseManager}/role/add.do";
					   }
				});
			 }
			
	 });

	 $("#totalDelete").click(function(){
	 	var radioData = $("input[name^='checkbox']").serialize();
		if(radioData!=""){
			$(".deleteAll").modal();//打开
		}else{
			alert("请选择需要删除的技师！");
		}
	 });
	 
	 
	 	//批量删除技师
		$("#deleteButton").click(function(){
			var count = 0;
			var checkboxData = $("input[name^='checkbox']").serialize();
			$("input[name='checkbox']").each(function(){
				if(this.checked==true){
					
				}
			});
			
			if(checkboxData.length != 0) {
				$.ajax({
				   type: "post",
				   dataType: "json",
				   url:  "${managerPath}/company/allDelete.do",
				   data: checkboxData,
				   beforeSend:function(){
				   		$("#deleteButton").text("删除中");
				   		$("#deleteButton").attr("disabled",true);
				   },
				   success: function(msg){
				   if(msg.result=="false"){
				   alert("存在某企业下仍存在技师无法删除！请先删除旗下技师！");
				   $("#deleteButton").attr("disabled",false);
				   $("#deleteButton").text("删除")
				   }else{
				   alert("删除技师成功");
				   		location.reload();
				   }
				   		
				   },error: function(){
				   	  alert("批量删除管理员失败");
				      $(".deleteAll").modal("hide");
				   }
				});
			 } else {
				alert("删除失败，请先选择管理员");
				$(".deleteAll").modal("hide");
			 }
		 });
		 
		 $("[id^='resetButton']").bind({
		 click:function(){
		 $("[name='enterpriseName']").val(function(){return ""});
		 $("#submitSearch").click();
		 }
		 })
</script>
</html>